<?php

namespace App\Models\Traits;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;

trait MorphToApprover
{
    /**
     * Notes   : 审核人
     *
     * @Date   : 2023/10/31 13:22
     * @Author : <Jason.C>
     * @return MorphTo
     */
    public function approver(): MorphTo
    {
        return $this->morphTo();
    }

    public function setApproverAttribute(Model $user): void
    {
        $this->attributes['approver_type'] = $user->getMorphClass();
        $this->attributes['approver_id'] = $user->getKey();
    }
}
